package main

import (
	"code.google.com/p/log4go"
	"fmt"
	"git.oschina.net/cnjack/nightc-download/downloader"
	"github.com/Unknwon/goconfig"
	"net/http"
	"os"
)

//配置的读取
func ReadConfig() {
	Dlist = make(map[string]*downloader.Down)
	conf, err := goconfig.LoadConfigFile("./conf.ini")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(0)
	}
	option.Port, err = conf.GetValue("downloader", "port")
	if err != nil {
		option.Port = "8081"
	}
	option.SaveRule, err = conf.GetValue("downloader", "saverule")
	if err != nil {
		option.SaveRule = "md5"
	}
	option.Savepath, err = conf.GetValue("downloader", "savepath")
	if err != nil {
		option.Savepath = "./"
	}
	option.LogPath, err = conf.GetValue("downloader", "logfile")
	if err != nil {
		option.LogPath = "./downloader.log"
	}
}
func WriteString(w http.ResponseWriter, s string) {
	w.Write([]byte(s))
}
func InitLog(logPath string) log4go.Logger {
	log := log4go.NewLogger()
	log.AddFilter("log", log4go.FINE, log4go.NewFileLogWriter(logPath, true))
	return log
}
